<template>
  <d2-container>
    <template slot="header">
      <el-form
        :gutter="24"
        @submit.native.prevent
        ref="search-box"
        :model="mainQuery"
        label-position="left"
        :inline="true"
      >
        <el-form-item label="拒付处理费表名" size="mini">
          <el-input
            placeholder=""
            v-model="mainQuery.name"
            @keyup.enter.native="handleSearch"
            size="small"
            clearable
          ></el-input>
        </el-form-item>
      </el-form>

      <div class="search-btn-box">
        <div class="left">
          <el-button-group>
            <el-button
              class="filter-item"
              icon="el-icon-circle-plus"
              type="success"
              @click="handleAdd"
              :loading="mainTable.loading"
              size="mini"
              >添加</el-button
            >
            <el-tooltip
              :disabled="!!mainTable.current"
              content="请选择一行数据"
            >
              <el-button
                class="filter-item"
                icon="el-icon-edit"
                type="default"
                @click="handleSet"
                :loading="mainTable.loading"
                size="mini"
                >修改</el-button
              >
            </el-tooltip>
            <el-tooltip
              :disabled="!!mainTable.current"
              content="请选择一行数据"
            >
              <el-button
                class="filter-item"
                type="default"
                @click="handleLog"
                :loading="mainTable.loading"
                size="mini"
                >变更日志</el-button
              >
            </el-tooltip>
          </el-button-group>
        </div>
        <div class="right">
          <el-button
            class="filter-item"
            icon=""
            type="default"
            @click="resetMainData"
            :loading="mainTable.loading"
            size="small"
            >重置</el-button
          >
          <el-button
            class="filter-item"
            icon="el-icon-search"
            type="primary"
            @click="handleSearch"
            :loading="mainTable.loading"
            size="small"
            >查询</el-button
          >
        </div>
      </div>
    </template>

    <!--主列表数据-->
    <d2-crud
      ref="d2Crud"
      :options="mainTable.options"
      :index-row="mainTable.indexRow"
      :columns="mainTable.columns"
      :data="mainTable.list"
      :selection-row="mainTable.allowSelect"
      :loading="mainTable.loading"
      @current-change="onMainCurrentChange"
      @row-dblclick="onMainDoubleClick"
      @selection-change=""
    ></d2-crud>

    <template slot="footer">
      <el-pagination
        @size-change="handleMainSizeChange"
        @current-change="handleMainPageChange"
        :current-page="mainTable.pagination.currentPage"
        :page-sizes="mainTable.pagination.pageSizes"
        :page-size="mainTable.pagination.pageSize"
        :page-count="mainTable.pagination.pageCount"
        :total="mainTable.pagination.total"
        layout="total, sizes, prev, pager, next, jumper"
        :background="true"
      >
      </el-pagination>
    </template>

    <dialog-add ref="dialog-add" @dialog-close="fetchMainData"></dialog-add>

    <dialog-log ref="dialog-log" @dialog-close="fetchMainData"></dialog-log>

    <common-export ref="common-export"></common-export>
  </d2-container>
</template>

<script>

import ApiMain from '@/api/mch.protest';
import DialogAdd from './dialog-add';
import DialogLog from './dialog-log';
import CommonExport from '../../common/export';
import util from '@/libs/util.js';

export default {
  name: 'mch-protest',
  mixins: [
  ],
  components: {
    'dialog-add': DialogAdd,
    'dialog-log': DialogLog,
    'common-export': CommonExport,
  },
  data() {
    return {

      mainQuery: {
        name: undefined,
      },

      mainTable: {
        loading: false,
        options: {
          border: true,
          stripe: true,
          highlightCurrentRow: true,
          emptyText: '暂无数据',
          size: 'mini',
        },
        // indexRow: {
        //   title:'序号',
        //   width: "80",
        //   align:'center'
        // },
        indexRow: null,
        allowSelect: false,
        columns: [
          // {title: 'id', key: 'id', align: 'center', showOverflowTooltip: true},
          { title: '拒付处理费表', key: 'name', align: 'center', showOverflowTooltip: true },
          { title: '修改人', key: 'createBy', align: 'center', showOverflowTooltip: true },
          { title: '修改时间', key: 'updateTime', align: 'center', showOverflowTooltip: true },
          // { title: '保证金解冻周期', key: 'bondWithdrawPeriod', align: 'center', showOverflowTooltip: true },
          // { title: '转账手续费', key: 'transPerFee', align: 'center', showOverflowTooltip: true },
          // { title: '提现手续费', key: 'withdrawPerFee', align: 'center', showOverflowTooltip: true },
          // { title: '修改时间', key: 'updateTime', align: 'center', showOverflowTooltip: true },
          // { title: '创建时间', key: 'createTime', align: 'center', showOverflowTooltip: true },
        ],
        list: [],
        pagination: {
          currentPage: 1,
          pageSize: 50,
          total: 0,
          pageSizes: [50, 100, 200]
        },
      },

    }
  },
  mounted() {
    this.resetMainData();
  },
  beforeDestroy() {
  },
  methods: {

    renderMainData(re) {
      this.mainTable.list = re.list;
      this.mainTable.pagination.total = re.total;
    },

    handleSearch() {
      this.mainTable.pagination.currentPage = 1;
      this.fetchMainData();
    },
    handleMainSizeChange(val) {
      this.mainTable.pagination.pageSize = val;
      this.mainTable.pagination.currentPage = 1;
      this.fetchMainData()
    },
    handleMainPageChange(val) {
      this.mainTable.pagination.page = val;
      this.fetchMainData()
    },

    buildMainQuery() {

      var query = {
        page: this.mainTable.pagination.currentPage,
        limit: this.mainTable.pagination.pageSize,
        search: this.mainQuery,
      };

      return query;
    },

    resetMainData() {

      this.mainQuery = {
        name: undefined,

      };

      this.fetchMainData();
    },

    async fetchMainData() {

      this.mainTable.loading = true;

      try {
        var re = await ApiMain.list(this.buildMainQuery());
        this.renderMainData(re);
      } catch (err) { }

      this.mainTable.loading = false;

    },

    onMainCurrentChange(now, old) {
      this.mainTable.current = now;
    },

    onMainDoubleClick(now) {
      this.mainTable.current = now;
      this.handleSet();
    },

    handleAdd() {
      this.$refs['dialog-add'].show();
    },

    handleSet() {
      if (this.mainTable.current) {
        this.$refs['dialog-add'].show(this.mainTable.current.id);
      }
    },

    handleLog() {
      if (this.mainTable.current) {
        this.$refs['dialog-log'].show(this.mainTable.current.id);
      }
    },

    handleExportExcel() {
      this.$refs['common-export'].handleExportExcel(ApiMain, this.mainQuery, true);
    },
  }
}
</script>

<style>
</style>
